if(!localStorage.getItem("token")) location.href="/login.html"

function creatData() {
    indexAPI(res=>{
                if(res.status===0) {  //这个判断里面是获取信息成功
            console.log(res);
            let {id,email,nickname,username,user_pic}=res.data
            if(nickname) username=nickname
            $(".username").text(username)
            if(!user_pic){  //如果没有图片就这样显示
                $(".avatar").css("display","inline-block").text(username[0].toUpperCase())
                $(".layui-nav-img").css("display","none")
            }else {
                $(".avatar").css("display","none")
                $(".layui-nav-img").css("display","inline-block").prop("src",user_pic) 
            }
        }else{
            localStorage.removeItem("token")
            location.href="/login.html"
        }
    })
}

creatData()
// console.log(window);
/* 完成点击跳转功能 */
$("#logout").on("click",function () {
    layer.confirm('是否退出?', {icon: 3, title:'帅哥提示'}, function(index){
        //do something
        localStorage.removeItem("token")
        location.href="/login.html"
        layer.close(index);
      });
})
// axios.get("http://api-breakingnews-web.itheima.net/my/userinfo",{headers:{Authorization:localStorage.getItem("token")} }